<template>
    <div class="player_box">
        <div class="my_palyer">
            <!-- 音乐图片及音乐名等 -->
            <div class="player_left">
                <div id="box">
                    <img src="https://img2.baidu.com/it/u=3832745967,4068295252&fm=253&fmt=auto&app=138&f=JPEG?w=901&h=500"
                        alt="">
                </div>
                <div class="music_name">九张机（《双世宠妃》主题曲）</div>
            </div>
            <!-- 播放按钮及菜单 -->
            <div class="player_right">
                <div class="player_btn" @click="playMusic">
                    <van-icon v-if="!isPlayer" name="play-circle-o" size="28" />
                    <van-icon v-else name="pause-circle-o" size="28" />
                </div>
                <div class="player_menu" @click="clickMenu">
                    <van-icon name="bars" size="28" />
                </div>
            </div>
        </div>
        <van-popup v-model:show="showBottom" round position="bottom" :style="{ height: '30%' }">
            <div class="right">
                <div class="right_top">当前播放列表</div>
                <div class="right_center">
                    <div>九张机<button>来源</button></div>
                    <div>冬眠</div>
                    <div>暮色回响</div>
                    <div>长安雪</div>
                    <div>小诗句</div>
                    <div>若梦</div>
                    <div>泡沫</div>
                    <div>不惜时光</div>
                </div>
                <div class="right_bottom">自动播放推荐歌曲</div>
                <div class="right_button">
                    <van-button plain round type="default" size="small">
                        <span class="right_text">+添加歌曲到列队</span>
                    </van-button>
                </div>
            </div>
        </van-popup>
    </div>
</template>
<script setup>
import { ref } from 'vue'



let isPlayer = ref(true)
let isRotate = ref(true)
// 弹出
let showBottom = ref(false)

const playMusic = () => {
    isPlayer.value = !isPlayer.value
    // 调用旋转事件
    toggleRotation()
}
// 旋转事件
function toggleRotation() {
    isRotate.value = !isRotate.value;
    if (isRotate.value) {
        document.getElementById('box').classList.remove('paused');
    } else {
        document.getElementById('box').classList.add('paused');
    }
}

// 点击音乐列表
const clickMenu = () => {
    console.log('点击了音乐列表');
    showBottom.value = true
}


</script>
<style scoped>
.player_box {
    height: 60px;
    position: fixed;
    padding: 10px;
    bottom: 0;
    background-color: #fff;
    border-top: 1px solid #ccc;
    width: 100%;
    box-sizing: border-box;

}

.my_palyer {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.my_palyer .player_left,
.my_palyer .player_right {
    display: flex;
    align-items: center;
}

.player_left img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
}

.music_name {
    color: #000;
    font-size: 15px;
    font-weight: 500;
    margin-left: 5px;
}

.player_btn {
    margin-right: 10px;
}

.right {
    padding-left: 10px;
}

.right_top {
    font-size: 20px;
    font-weight: bolder;
    position: sticky;
    top: 0px;
    right: 20px;
    padding-top: 10px;
    background-color: #fff;
    border-bottom: 1px solid #ccc;
    width: 100%;
    box-sizing: border-box;
    height: calc(10vh - 10px);
    overflow-y: scroll;
}

.right_center {
    font-size: 15px;
    padding-top: 20px;
    background-color: aliceblue;

}

.right_bottom {
    font-size: 17px;
    padding-top: 10px;
    color: #ccc;
}

.right_button {
    text-align: center;
    padding-top: 10px;

}

#box {
    animation: musicRotate 2s infinite linear;
}

#box.paused {
    animation-play-state: paused;
}


/* 定义音乐图片旋转的动画 */
@keyframes musicRotate {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}
</style>
